package com.dream.technology.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.dream.technology.db.entity.RcCustomerTag;
import com.dream.technology.db.entity.RcCustomerTagItem;
import com.dream.technology.db.entity.RcCustomerTagItemQuery;
import com.dream.technology.data.GenericRspDTO;
import com.dream.technology.service.RcCustomerTagItemService;
import com.dream.technology.vo.ErrorCode;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/risk/admin/customer_tag_item")
public class RcCustomerTagItemController {

    private static final Logger logger = LoggerFactory.getLogger(RcCustomerTagItemController.class);

    @Autowired
    RcCustomerTagItemService rcCustomerTagItemService;

    /**
     * 用户标签设置项列表接口
     * @param pageNum
     * @param pageSize
     * @param tagName
     * @param typeName
     * @return
     */
    @GetMapping("/list")
    public GenericRspDTO<Object> getList(Integer pageNum, Integer pageSize, String name, String typeName){


        RcCustomerTagItemQuery query=new RcCustomerTagItemQuery();
        RcCustomerTagItemQuery.Criteria criteria = query.createCriteria();
        PageHelper.startPage(pageNum,pageSize);
        List<RcCustomerTagItem> RcFieldSelectList = rcCustomerTagItemService.selectByExample(query);
        PageInfo pageInfo = new PageInfo(RcFieldSelectList);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), pageInfo);
    }

    /**
     *  获取用户标签设置项回显接口
     * @param id
     * @return
     */
    @GetMapping("/id")
    public GenericRspDTO<RcCustomerTagItem> getRcCustomerTagItemById(Long id){

        RcCustomerTagItem rcCustomerTagItem = rcCustomerTagItemService.selectByPrimaryKey(id);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), rcCustomerTagItem);

    }

    /**
     *  添加用户标签设置项
     * @param rcCustomerTagItem
     * @return
     */
    @PostMapping("/add")
    public GenericRspDTO<Object> addRcCustomerTagItem(RcCustomerTagItem rcCustomerTagItem){

        rcCustomerTagItemService.insert(rcCustomerTagItem);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);

    }

    /**
     * 修改用户标签设置项接口
     * @param rcCustomerTagItem
     * @return
     */
    @PostMapping("/update")
    public GenericRspDTO<Object> updateRcCustomerTagItem(RcCustomerTagItem rcCustomerTagItem){

        rcCustomerTagItemService.updateByPrimaryKeySelective(rcCustomerTagItem);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);

    }

    /**
     * 删除用用户标签设置项 (逻辑删除)
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public GenericRspDTO<Object> deleteRcCustomerTagItem(Long id){

        rcCustomerTagItemService.deleteByPrimaryKey(id);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }




    /**
     * 风控用户标签元素修改前检查 返回引用该标签元素的标签集合
     *
     * @param
     * @return
     */
    @PostMapping("/checkRef")
    public GenericRspDTO<Object> updateBeforeCheck(Long customerTagItem) {
        List<RcCustomerTag> result = rcCustomerTagItemService.queryCustomerTagByItem(customerTagItem);
        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), result);
    }
}
